home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Embed / Sources / Content.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.2 KB  |  180 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Content.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef CONTENT_H
  15. #include "Content.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef PROXY_H
  23. #include "Proxy.h"
  24. #endif
  25.  
  26. #ifndef FRAME_H
  27. #include "Frame.h"
  28. #endif
  29.  
  30. #ifndef FWPRESEN_H
  31. #include "FWPresen.h"
  32. #endif
  33.  
  34. // ----- OpenDoc Includes -----
  35.  
  36. #ifndef SOM_Module_OpenDoc_StdProps_defined
  37. #include <StdProps.xh>
  38. #endif
  39.  
  40. //========================================================================================
  41. //    Runtime information
  42. //========================================================================================
  43.  
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment odfembed
  46. #endif
  47.  
  48. FW_DEFINE_AUTO(CEmbedContent)
  49.  
  50. //========================================================================================
  51. //    CLASS CEmbedContent
  52. //========================================================================================
  53.  
  54. //----------------------------------------------------------------------------------------
  55. // CEmbedContent constructor
  56. //----------------------------------------------------------------------------------------
  57.  
  58. CEmbedContent::CEmbedContent(Environment* ev, CEmbedPart* part)
  59. :    FW_CEmbeddingContent(ev, part),
  60.     fEmbedPart(part),
  61.     fProxy(NULL)
  62. {
  63. }
  64.  
  65. //----------------------------------------------------------------------------------------
  66. //    CEmbedContent destructor
  67. //----------------------------------------------------------------------------------------
  68.  
  69. CEmbedContent::~CEmbedContent()
  70. {
  71.     delete fProxy;
  72.     fProxy = NULL;
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------
  76. //    CEmbedContent::Externalize
  77. //----------------------------------------------------------------------------------------
  78.  
  79. void CEmbedContent::Externalize(Environment* ev,
  80.                                  ODStorageUnit* storageUnit,
  81.                                  FW_EStorageKinds storageKind,
  82.                                  FW_CCloneInfo* cloneInfo)
  83. {
  84.     // ----- Create an archive -----
  85.     FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fEmbedPart->GetPartKind(ev));
  86.     FW_CWritableStream archive(suSink);
  87.     
  88.     // ----- Write number of embedded parts -----
  89.     unsigned long count = (fProxy ? 1 : 0);
  90.     archive << count;
  91.     
  92.     // ----- Write embedded part -----
  93.     if (fProxy)
  94.         fProxy->Externalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
  95. }
  96.  
  97. //----------------------------------------------------------------------------------------
  98. //    CEmbedContent::Internalize
  99. //----------------------------------------------------------------------------------------
  100.  
  101. FW_Boolean CEmbedContent::Internalize(Environment* ev,
  102.                                        ODStorageUnit* storageUnit, 
  103.                                        FW_EStorageKinds storageKind,
  104.                                        FW_CCloneInfo* cloneInfo)
  105. {
  106.     if (!storageUnit->Exists(ev, kODPropContents, fEmbedPart->GetPartKind(ev), 0))
  107.         return false;
  108.  
  109.     // ----- Create an archive -----
  110.     FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fEmbedPart->GetPartKind(ev));
  111.     FW_PBufferedSink sink(ev, suSink);
  112.     FW_CReadableStream archive(sink);
  113.     
  114.     // ----- Read number of embedded parts -----
  115.     unsigned long count;
  116.     archive >> count;
  117.     
  118.     // ----- Read embedded part, if any -----
  119.     if (count == 1)
  120.     {
  121.         fProxy = new CEmbedProxy(ev, fEmbedPart, fEmbedPart->GetPresentation());
  122.         fProxy->Internalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
  123.     }    
  124.  
  125.     if (storageKind != FW_kPartStorage)
  126.         fEmbedPart->Changed(ev);
  127.         
  128.     return true;
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    CEmbedContent::SingleEmbeddedFrameInternalized
  133. //----------------------------------------------------------------------------------------
  134.  
  135. void CEmbedContent::SingleEmbeddedFrameInternalized(Environment* ev,
  136.                                                     FW_CEmbeddingFrame* scopeFrame,
  137.                                                     ODPart* odEmbeddedPart, 
  138.                                                     ODFrame* odEmbeddedFrame,
  139.                                                     ODShape* suggestedShape,
  140.                                                     ODTypeToken viewType)
  141. {
  142.     // ----- Detach existing proxy, if any -----
  143.     if (fProxy)
  144.     {
  145.         fProxy->SetSelectState(ev, false);
  146.         fProxy->DetachEmbeddedFrames(ev);
  147.     }
  148.  
  149.     // ----- Calculate the frame shape -----
  150.     FW_CAcquiredODShape aqFrameShape = ((CEmbedFrame*)scopeFrame)->MakeFrameShape(ev);
  151.         
  152.     // ----- Create the proxy -----
  153.     CEmbedProxy* newProxy = new CEmbedProxy(ev, fEmbedPart, scopeFrame->GetPresentation(ev));
  154.     
  155.     // ----- Embed the Part/Frame -----
  156.     scopeFrame->GetPresentation(ev)->Embed(ev, 
  157.                                             odEmbeddedPart, 
  158.                                             odEmbeddedFrame,
  159.                                             kODFrameObject,
  160.                                             newProxy, 
  161.                                             aqFrameShape, 
  162.                                             viewType, 
  163.                                             NULL,        // no presentation
  164.                                               0,            // group id
  165.                                               FALSE,        // is Overlaid
  166.                                               false);        // sub-frame?
  167.  
  168.     // ----- Set the proxy  -----
  169.     fProxy = newProxy;
  170. }
  171.  
  172. //----------------------------------------------------------------------------------------
  173. //    CEmbedContent::IsDataOnlyOneProxy
  174. //----------------------------------------------------------------------------------------
  175.  
  176. FW_MProxy* CEmbedContent::IsDataOnlyOneProxy(Environment* ev) const
  177. {
  178.     return fProxy;
  179. }
  180.